# author:lizhubo
# date:week

# author:lizhubo
# date:week

print("购物车程序")
print("亲，你好，请先登录")
# 模拟数据库数据
user_data = ["lizhubo","lihui","guosiwen"]
password_data = ["123"]

# 输入次数(只有三次登录的机会)
# 登陆中
username = input("账号：")
password = input("密码：")

if username in user_data:
    if password in password_data:
        print("欢迎",username,"进入网站","祝您购物愉快")


product_list = [
    ("草莓碎碎冰",19),('芝士葡萄',24),
     ('西瓜椰椰',13),('珍奶',12),('四季奶青',12)
]

shopping_car=[]
shopping_car_total = []
balance =input('请输入支付宝余额:')

while True:
    balance=int(balance)
    for item in product_list:
        print(product_list.index(item),item)
    choice=input('请输入产品编号')
    if choice.isdigit():
        choice = int(choice)
        if choice >= 0 and choice < 5:
            if balance >= product_list[choice][1]:
                balance = balance-product_list[choice][1]
                shopping_car.append(product_list[choice][0])
                shopping_car_total.append(product_list[choice][1])
                print("你把商品%s添加到购物车,支付宝余额是%s元"%(product_list[choice][0],balance))
                print("购物车：",shopping_car)
                print('默认继续购买,若不想购买请按q键退出')
            else:
                print('你的余额不足,请重新选择商品')
                print('或者请按Q或q退出')
        else:
            print('商品里没有这个列表，请重新选择一个商品')
    elif choice =='Q'or'q':
        print('-----购物车清单----')
        for item in shopping_car:
            print(item)
        a = len(shopping_car)

        print('数量:%s件商品'%a)
        print("合计为: ", sum(shopping_car_total),'元')
        print('你的支付宝余额为%s元'%balance)
        print('已购买{}'.format(shopping_car))
        break
    else:
        print('请按退出程序')
